package jdbc;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class TestSelect2 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:mysql://localhost:3306/java75?useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&allowMultiQueries=true";
        Connection con = null;
        Statement st = null;

        try {
            con = DriverManager.getConnection(url, "root", "root1234");
            System.out.println(con.getClass().getName());
            st = con.createStatement();
            System.out.println(st.getClass().getName());
            String sql="insert into s_subject(subjectname,classhour,gradeid)values('核潜艇维修大全',100,7)";
            int res = st.executeUpdate(sql);
            System.out.printf("成功影响了%d行",res);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

            try {

                if (st != null)
                    st.close();

            } catch (Exception e) {
                e.printStackTrace();
            }
            try {

                if (con != null)
                    con.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
